home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows 95 API Bible
/
Windows 95 API Bible 3 Disc Set.iso
/
Win32 API Bible Book 1 of 3.iso
/
chapte25
/
ex17.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-23
|
2KB
|
62 lines
#include <genstub.c>
// Define these options in an rc file.
#define IDM_INC 201 // &Increment
#define IDM_DEC 202 // &Decrement
#define IDM_EXC 203 // &Exchange
// Windows message procedure.
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static HANDLE hMap = 0;
static LONG *lpData = NULL;
switch (uMsg) {
case WM_CREATE:
// Create file mapping object.
hMap = CreateFileMapping( (HANDLE) 0xFFFFFFFF, NULL,
PAGE_READWRITE, 0, 4096,
"SHARED_VALUE");
lpData = (LONG *) MapViewOfFile( hMap, FILE_MAP_ALL_ACCESS,
0, 0, 4 );
return DefWindowProc( hWnd, uMsg, wParam, lParam );
case WM_COMMAND:
{
TCHAR szOperation[128];
*szOperation = 0;
switch ( LOWORD( wParam ) )
{
case IDM_INC:
InterlockedIncrement( lpData );
lstrcpy( szOperation, "Increment" );
break;
case IDM_DEC:
InterlockedDecrement( lpData );
lstrcpy( szOperation, "Decrement" );
break;
case IDM_EXC:
InterlockedExchange( lpData, (LONG)hWnd );
lstrcpy( szOperation, "Exchange" );
break;
case IDM_EXIT:
DestroyWindow( hWnd );
break;
}
if ( *szOperation )
{
TCHAR szBuffer[128];
wsprintf( szBuffer, "Interlocked Value: %ld", *lpData );
MessageBox( hWnd, szBuffer, szOperation, MB_OK );
}
}
break;
case WM_DESTROY:
if ( hMap )
CloseHandle( hMap );
PostQuitMessage( 0 );
break;
default:
return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
return NULL;
}